package com.itheima.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;

@Configuration
@EnableConfigurationProperties({RedisProperties.class})
@ConditionalOnClass({Jedis.class})
public class RedisAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean({Jedis.class})
    public Jedis jedis(RedisProperties redisProperties) {
        System.out.println("当前的host为:" + redisProperties.getHost() + ",端口号为:" + redisProperties.getPort());
        Jedis jedis = new Jedis(redisProperties.getHost(), redisProperties.getPort());
        return jedis;
    }
}
